
import service from "../../utils/request";
import type { AxiosPromise } from "axios";
import type { NoticeInsertVO, NoticeVO, NoticeQuery } from "./types";

export const getNoticeDetail = (announId: number): AxiosPromise<NoticeVO> => {
  return service({
    url: `/announcements/${announId}`,
    method: "GET",
  });
};

export const deleteNoticeById = (announId: number): AxiosPromise<boolean> => {
  return service({
    url: `/announcements/${announId}`,
    method: "DELETE",
  });
};

export const createNotice = (notice: NoticeInsertVO): AxiosPromise<boolean> => {
  return service({
    url: `/announcements/createAnnouncement`,
    method: "POST",
    data: notice,
  });
};

export const groupNoticesByType = (query: any): AxiosPromise<any> => {
  return service({
    url: `/announcements/group`,
    method: "POST",
    data: query,
  });
};

export const updateNoticeById = (
  data: {
    announId: number;
    title: string;
    content: string;
    status?: string;
    type?: string;
    userIds?: number[];
  }
): AxiosPromise<boolean> => {
  return service({
    url: "/announcements/update",
    method: "PUT",
    data,
  });
};

export const getNoticesByPage = (query: NoticeQuery): AxiosPromise<any> => {
  return service({
    url: `/announcements/page`,
    method: "POST",
    data: query,
  });
};